
var primaryClassification=[]//一级分类信息
var secondaryClassification=[]//二级分类信息
var tertiaryClassification=[]//三级分类信息
var levelfourClassification=[]//四级分类信息
var secondaryClasscancel=[]//取消的二级信息
var tertiaryClassificationall=[]//所有三级分类
var primaryAddress=[]//一级地址信息
var secondaryAddress=[]//一级地址信息

freeFreight()
function freeFreight(){
    var user_data = {
    }
    var succCallBack = function (data, status, response) {
        primaryClassification=[]
        secondaryClassification=[]
        tertiaryClassification=[]
        secondaryAddress=[]
        primaryAddress=[]
        if(data.data!=null){
            $("#amount").val(data.data.amount)
            console.log(data.data.status)
            if(data.data.status==0){
                $("#statusall").html('<span id="status" style="display: none">0</span><a onclick="statusbutton(1,'+data.data.id+')">启用</a>')
            }else  if(data.data.status==1){
                $("#statusall").html('<span id="status" style="display: none">1</span><a onclick="statusbutton(0,'+data.data.id+')">禁用</a>')
            }
            for (var i=0;i<data.data.categoryIdOne.length;i++) {
                primaryClassification.push(Number(data.data.categoryIdOne[i]))
            }
            for (var i=0;i<data.data.categoryIdTwo.length;i++) {
                secondaryClassification.push(Number(data.data.categoryIdTwo[i]))
            }
            for (var i=0;i<data.data.categoryIdThree.length;i++) {
                tertiaryClassification.push(Number(data.data.categoryIdThree[i]))
            }
            for (var i=0;i<data.data.categoryId.length;i++) {
                levelfourClassification.push(Number(data.data.categoryId[i]))
            }
            for (var i=0;i<data.data.provinceCode.length;i++) {
                primaryAddress.push(Number(data.data.provinceCode[i]))
            }
            for (var i=0;i<data.data.cityCode.length;i++) {
                secondaryAddress.push(Number(data.data.cityCode[i]))
            }
            goods_listCategory1(1);
            addressinformation1(101);
        }else {
            primaryClassification=[]
            secondaryClassification=[]
            tertiaryClassification=[]
            levelfourClassification=[]
            secondaryAddress=[]
            primaryAddress=[]
            $("#amount").val("")
            $("#statusall").html('<span id="status" style="display: none">0</span><a onclick="statusbutton(3)">启用</a>')
            goods_listCategory1(1);
            addressinformation1(101);
            $("#classDiv2").css({
                display: "none"
            });
            $("#classDiv3").css({
                display: "none"
            });
            $("#classDiv4").css({
                display: "none"
            });
            $("#addressdiv2").css({
                display: "none"
            });

        }
    };
    return web.doAjax(root.logistics.freeFreight, 'get', user_data, succCallBack);
}
function statusbutton(val,id){
    if(val==3){
        //未配置数据
        layer.msg("规则未配置完毕", {
            icon: 5,
            time: 1000
        }, function() {
        });
    }else {
        var text=''
        if(val==1){
            text='确定要禁用吗?'
        }else {
            text='确定要启用吗?'
        }

        layer.confirm(''+text+'', function(index) {
            var user_data = {}
            var succCallBack = function (data, status, response) {
                if(data.errorCode == 0) {
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                    if(val==1){
                        layer.msg("禁用成功", {
                            icon: 6,
                            time: 1000
                        }, function() {
                            freeFreight();
                        });
                    }else {
                        layer.msg("启用成功", {
                            icon: 6,
                            time: 1000
                        }, function() {
                            freeFreight();
                        });
                    }

                } else {
                    layer.msg(data.msg, {
                        icon: 5,
                        time: 1000
                    }, function() {
                        freeFreight();
                    });
                }
            };
            return web.doAjax(root.logistics.freeFreight+'/'+val+'?id='+id+'', 'PUT', user_data, succCallBack);

        });
    }

}
/*分类信息*/
//一级
goods_listCategory1(1);
function goods_listCategory1(classNum) {

    var user_data = {
        category_level: classNum
    }
    var succCallBack = function (data, status, response) {
        if (data.data.length == 0) {
            $("#classSet1").html('<li class="clearfix pl-10 mb-5"  style="width: 95%" >无数据</li>');
        }
        else {
            console.log(primaryClassification)
            var classSet1=''
            for (var i = 0; i < data.data.length; i++) {
                var categoryId = data.data[i].category_id;
                if ($.inArray(categoryId, primaryClassification) != -1) {
                    classSet1+='<li class="clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5">' +
                        '<input id="' + data.data[i].category_id + '" onclick="nextbox1(this,'+data.data[i].category_code+',' +data.data[i].category_id + ')" name="classification01" type="checkbox" data-level="'+data.data[i].category_level+'" checked="checked" data-name="'+data.data[i].category_name+'" value="' + data.data[i].category_id + '" class="checkbox" />' +
                        '<label id="' + data.data[i].category_id + 'q" class="pl-10"  onclick="isFirstClick(2,' +data.data[i].category_id + ',this)">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div>' +
                        '</div></li>'
                } else {
                    classSet1+='<li class="clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5">' +
                        '<input id="' + data.data[i].category_id + '" onclick="nextbox1(this,'+data.data[i].category_code+',' +data.data[i].category_id + ')" name="classification01" type="checkbox" data-level="'+data.data[i].category_level+'" data-name="'+data.data[i].category_name+'" value="' + data.data[i].category_id + '" class="checkbox" />' +
                        '<label id="' + data.data[i].category_id + '" class="pl-10"  onclick="isFirstClick(2,' +data.data[i].category_id + ',this)">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div>' +
                        '</div></li>'
                }

            }
            $("#classSet1").html(classSet1)
        }
    };
    return web.doAjax(root.goodsInter.goods_listCategory, 'post', user_data, succCallBack);
}

function nextbox1(that) {
    var primaryClassificationval = parseInt(that.value);
    if(that.checked){

        primaryClassification.push(primaryClassificationval)
        $("#classDiv3").css({
            display: "none"
        });
        $("#classDiv4").css({
            display: "none"
        });
    } else{
        $("#classDiv2").css({
            display: "none"
        });
        $("#classDiv3").css({
            display: "none"
        });
        $("#classDiv4").css({
            display: "none"
        });
        for (var i = 0; i < primaryClassification.length; i++) {
            if (primaryClassification[i] == primaryClassificationval) {
                primaryClassification.splice(i, 1);
                i--;
            }
        }
    }
    console.log(primaryClassification)
    goods_listCategory2(1,primaryClassificationval,that.nextElementSibling)//渲染二级类
}
//二级分类
function goods_listCategory2(classNum, parentId, e) {
    console.log(secondaryClassification)
    if(e.previousElementSibling.checked){
        var checkbox = e.previousElementSibling;
        $(".removeEl2").remove();
        $("#classDiv2").css({
            display: "block"
        });
        var user_data = {
            category_id: parentId
        }
        var succCallBack = function (data, status, response) {
            if (data.data.length == 0) {
                $("#classSet2").html('<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" >无数据</li>');
            }
            else {
                var classSet2=''
                //有数据
                for (var i = 0; i < data.data.length; i++) {
                    if(classNum==1){
                        secondaryClassification.push(data.data[i].category_id)

                    }
                    var categoryId = data.data[i].category_id;
                    if (checkbox.checked) {
                        if ($.inArray(categoryId, secondaryClassification) != -1) {
                            classSet2+='<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox2(this,' + data.data[i].category_code + ',' + parentId + ')" name="classification02" type="checkbox" data-level="' + data.data[i].category_level + '" data-name="' + data.data[i].category_name + '" value="' + data.data[i].category_id + '" checked="checked" class="" /><label class="pl-10 secondlevel"  onclick="goods_listCategory3(3,' + data.data[i].category_id + ',this)">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>'
                        } else {
                            classSet2+='<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5"><input onclick="nextbox2(this,' + data.data[i].category_code + ',' + parentId + ')"  name="classification02" type="checkbox" data-level="' + data.data[i].category_level + '" data-name="' + data.data[i].category_name + '" value="' + data.data[i].category_id + '"  class="" /><label class="pl-10 secondlevel" onclick="goods_listCategory3(3,' + data.data[i].category_id + ',this)">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>'
                        }
                    }
                }
                $("#classSet2").html(classSet2)
                tertiaryClassifications(1)
            }
        };
        return web.doAjax(root.goodsInter.goods_subCategory, 'post', user_data, succCallBack);
    }else {
        secondaryClasscancel=[]
        var user_data2 = {
            category_id: parentId
        }
        var succCallBack2 = function (data, status, response) {
            for (var i = 0; i < secondaryClassification.length; i++) {
                for (var h = 0; h < data.data.length; h++) {
                    var categoryId = data.data[h].category_id;
                    if (secondaryClassification[i] == categoryId) {
                        secondaryClassification.splice(i, 1);
                        i--;
                    }
                }
            }
            for (var d = 0; d < data.data.length; d++) {
                secondaryClasscancel.push(data.data[d].category_id)
            }
            tertiaryClassifications(2)
        };
        return web.doAjax(root.goodsInter.goods_subCategory, 'post', user_data2, succCallBack2);

    }
}
//获取所有三级分类
function tertiaryClassifications(val) {
    var secondaryClassificationall=""
    if(val==1){
        secondaryClassificationall=secondaryClassification
    }else if(val==2){
        secondaryClassificationall=secondaryClasscancel
    }
    $.ajax({
        url: root.goodsInter.subCategorys,
        contentType: "application/json;charset=UTF-8",
        cache: false,  //禁用缓存
        type: "POST",
        dataType: 'json',
        async:false,//优先运行
        data: JSON.stringify(secondaryClassificationall),
        success: function (data) {
            tertiaryClassificationall=[]
            for (var m=0;m<data.data.length;m++) {
                tertiaryClassificationall.push(Number(data.data[m].category_id))
            }
            if(val==1){
                //保存全部三级
                tertiaryClassification=[]
                for (var f=0;f<data.data.length;f++) {
                    tertiaryClassification.push(Number(data.data[f].category_id))
                }
                levelfourClassifications(1)
            }else if(val==2){
                for (var d=0;d<data.data.length;d++){
                    for (var i = 0; i < tertiaryClassification.length; i++) {
                        var category_id=data.data[d].category_id
                        if (tertiaryClassification[i] == category_id) {
                            tertiaryClassification.splice(i, 1);
                            i--;
                        }
                    }
                }
                levelfourClassifications(2)
            }

        }
    });
}
//获取所有四级分类
function levelfourClassifications(val) {
    $.ajax({
        url: root.goodsInter.subCategorys,
        contentType: "application/json;charset=UTF-8",
        cache: false,  //禁用缓存
        type: "POST",
        dataType: 'json',
        async:false,//优先运行
        data: JSON.stringify(tertiaryClassificationall),
        success: function (data) {
            if(val==1){
                //保存全部四级
                levelfourClassification=[]
                for (var f=0;f<data.data.length;f++) {
                    levelfourClassification.push(Number(data.data[f].category_id))
                }
            }else if(val==2){
                console.log(levelfourClassification)
                for (var d=0;d<data.data.length;d++){
                    for (var i = 0; i < levelfourClassification.length; i++) {
                        var category_id=data.data[d].category_id
                        if (levelfourClassification[i] == category_id) {
                            levelfourClassification.splice(i, 1);
                            i--;
                        }
                    }
                }

            }
            console.log(levelfourClassification)
        }
    });
}
function nextbox2(that,valCode,parentId) {
    var secondaryClassificationval = parseInt(that.value);
    if(that.checked){
        secondaryClassification.push(secondaryClassificationval)
    } else{
        $("#classDiv3").css({
            display: "none"
        });
        $("#classDiv4").css({
            display: "none"
        });

        for (var i = 0; i < secondaryClassification.length; i++) {
            if (secondaryClassification[i] == secondaryClassificationval) {
                secondaryClassification.splice(i, 1);
                i--;
            }
        }
    }
    goods_listCategory3(33,secondaryClassificationval,that.nextElementSibling)
}
function isFirstClick(classNum, parentId, e) {
    goods_listCategory2(classNum, parentId, e)//渲染二级类
}
//三级分类
function goods_listCategory3(classNum, parentId, e) {
    if(e.previousElementSibling.checked){
        var checkbox = e.previousElementSibling;
        $(".removeEl3").remove();
        $("#classDiv3").css({
            display: "block"
        });
        $("#classDiv4").css({
            display: "none"
        });
        var user_data = {
            category_id: parentId
        }
        var succCallBack = function (data, status, response) {
            if (data.data.length == 0) {
                $("#classSet3").html('<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" >无数据</li>');
            }
            else {

                var classSet3=''
                //有数据
                for (var i = 0; i < data.data.length; i++) {
                    var categoryId = data.data[i].category_id;
                    if(classNum==33){
                        tertiaryClassification.push(categoryId)
                        levelfourClassifications(1)
                    }
                    if (checkbox.checked) {
                        if ($.inArray(categoryId, tertiaryClassification) != -1) {
                            classSet3+='<li class="removeEl3 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox3(this,' + data.data[i].category_code + ',' + parentId + ')" name="classification02" type="checkbox" data-level="' + data.data[i].category_level + '" data-name="' + data.data[i].category_name + '" value="' + data.data[i].category_id + '" checked="checked" class="" /><label class="pl-10 secondlevel"  onclick="goods_listCategory4(4,' + data.data[i].category_id + ',this)">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>'
                        } else {
                            classSet3+='<li class="removeEl3 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5"><input onclick="nextbox3(this,' + data.data[i].category_code + ',' + parentId + ')"  name="classification02" type="checkbox" data-level="' + data.data[i].category_level + '" data-name="' + data.data[i].category_name + '" value="' + data.data[i].category_id + '"  class="" /><label class="pl-10 secondlevel"  onclick="goods_listCategory4(4,' + data.data[i].category_id + ',this)">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>'
                        }
                    }
                }
                $("#classSet3").html(classSet3)
            }
        };
        return web.doAjax(root.goodsInter.goods_subCategory, 'post', user_data, succCallBack);
    }else {
        tertiaryClassificationall=[]
        var user_data2 = {
            category_id: parentId
        }
        var succCallBack2 = function (data, status, response) {
            for (var i = 0; i < tertiaryClassification.length; i++) {
                for (var h = 0; h < data.data.length; h++) {
                    var categoryId = data.data[h].category_id;
                    if (tertiaryClassification[i] == categoryId) {
                        tertiaryClassification.splice(i, 1);
                        i--;
                    }
                }
            }
            for (var d = 0; d < data.data.length; d++) {
                tertiaryClassificationall.push(data.data[d].category_id)
            }
            levelfourClassifications(2)
        };
        return web.doAjax(root.goodsInter.goods_subCategory, 'post', user_data2, succCallBack2);
    }
}
function nextbox3(that,valCode,parentId) {
    var tertiaryClassificationval = parseInt(that.value);
    if(that.checked){
        tertiaryClassification.push(tertiaryClassificationval)
    } else{
        $("#classDiv4").css({
            display: "none"
        });
        for (var i = 0; i < tertiaryClassification.length; i++) {
            if (tertiaryClassification[i] == tertiaryClassificationval) {
                tertiaryClassification.splice(i, 1);
                i--;
            }
        }
    }
    goods_listCategory4(44,tertiaryClassificationval,that.nextElementSibling)
}
//四级分类
function goods_listCategory4(classNum, parentId, e) {
    if(e.previousElementSibling.checked){
        var checkbox = e.previousElementSibling;
        $(".removeEl4").remove();
        $("#classDiv4").css({
            display: "block"
        });
        var user_data = {
            category_id: parentId
        }
        var succCallBack = function (data, status, response) {
            if (data.data.length == 0) {
                $("#classSet4").html('<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" >无数据</li>');
            }
            else {
                var classSet3=''
                //有数据
                for (var i = 0; i < data.data.length; i++) {
                    var categoryId = data.data[i].category_id;
                    console.log(levelfourClassification)
                    if(classNum==44){
                        levelfourClassification.push(categoryId)
                    }
                    if (checkbox.checked) {
                        if ($.inArray(categoryId, levelfourClassification) != -1) {
                            classSet3+='<li class="removeEl4 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="nextbox4(this,' + data.data[i].category_code + ',' + parentId + ')" name="classification02" type="checkbox" data-level="' + data.data[i].category_level + '" data-name="' + data.data[i].category_name + '" value="' + data.data[i].category_id + '" checked="checked" class="" /><label class="pl-10 secondlevel"  >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>'
                        } else {
                            classSet3+='<li class="removeEl4 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5"><input onclick="nextbox4(this,' + data.data[i].category_code + ',' + parentId + ')"  name="classification02" type="checkbox" data-level="' + data.data[i].category_level + '" data-name="' + data.data[i].category_name + '" value="' + data.data[i].category_id + '"  class="" /><label class="pl-10 secondlevel" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>'
                        }
                    }
                }
                $("#classSet4").html(classSet3)
            }
        };
        return web.doAjax(root.goodsInter.goods_subCategory, 'post', user_data, succCallBack);
    }else {
        //三级取消
        var user_data2 = {
            category_id: parentId
        }
        var succCallBack2 = function (data, status, response) {
            for (var i = 0; i < levelfourClassification.length; i++) {
                for (var h = 0; h < data.data.length; h++) {
                    var categoryId = data.data[h].category_id;
                    if (levelfourClassification[i] == categoryId) {
                        levelfourClassification.splice(i, 1);
                        i--;
                    }
                }
            }
        };
        return web.doAjax(root.goodsInter.goods_subCategory, 'post', user_data2, succCallBack2);
    }
}
function nextbox4(that,valCode,parentId) {
    var tertiaryClassificationval = parseInt(that.value);
    if(that.checked){
        levelfourClassification.push(tertiaryClassificationval)
    } else{
        for (var i = 0; i < levelfourClassification.length; i++) {
            if (levelfourClassification[i] == tertiaryClassificationval) {
                levelfourClassification.splice(i, 1);
                i--;
            }
        }
    }
}
/*地址信息*/
/*一级全选*/
var secondaryids=""
var secondarybtun=""
var ressindatalength=""
function primaryallselection(){
    primaryAddress=[]
    $("#addressdiv2").css({
        display: "none"
    });
    var user_data = {
        level: 101,
    }
    var succCallBack = function (data, status, response) {
        for (var i = 0; i < data.list.length; i++) {
            var categoryId = data.list[i].code;
            if ($("#primaryallselection").is(':checked') == true) {
                primaryAddress.push(Number(categoryId))
                $("#secondaryallselection").attr("checked","checked")
            } else {
                primaryAddress=[]
            }
        }
        addressinformation1(101);
    };
    return web.doAjax(root.member.getLowerAddress, 'post', user_data, succCallBack);

}

//一级
addressinformation1(101);
function addressinformation1(classNum) {
    var user_data = {
        level: classNum,
    }
    var succCallBack = function (data, status, response) {
        if (data.list.length == 0) {
            $("#address1").html('<li class="clearfix pl-10 mb-5"  style="width: 95%" >无数据</li>');
        }
        else {
            var address1=''
            for (var i = 0; i < data.list.length; i++) {
                var codedata= data.list[i]
                var categoryId =codedata.code;
                if ($.inArray(Number(categoryId), primaryAddress) != -1) {
                    address1+='<li class="clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5">' +
                        '<input id="' + codedata.code + '" onclick="selectdata1(this,'+codedata.code+')" name="classification01" type="checkbox"  checked="checked"  value="' + codedata.code + '" class="checkbox" />' +
                        '<label id="' + codedata.code + '" class="pl-10"  onclick="renderdata(2,' +codedata.code + ',this)">' + codedata.alias_name + '</label></div>' +
                        '</div></li>'
                } else {
                    address1+='<li class="clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5">' +
                        '<input id="' + codedata.code + '" onclick="selectdata1(this,'+codedata.address_id+')" name="classification01" type="checkbox" value="' + codedata.code + '" class="checkbox" />' +
                        '<label id="' + codedata.code + '" class="pl-10"  onclick="renderdata(2,' +codedata.code + ',this)">' + codedata.alias_name + '</label></div>' +
                        '</div></li>'
                }

            }
            $("#address1").html(address1)
        }
    };
    return web.doAjax(root.member.getLowerAddress, 'post', user_data, succCallBack);
}

function selectdata1(that,address_id) {
    var primaryAddressval = parseInt(that.value);
    secondaryids=primaryAddressval
    secondarybtun=that.nextElementSibling
    if(that.checked){
        primaryAddress.push(Number(primaryAddressval))
    } else{
        $("#addressdiv2").css({
            display: "none"
        });
        for (var i = 0; i < primaryAddress.length; i++) {
            if (primaryAddress[i] == primaryAddressval) {
                primaryAddress.splice(i, 1);
                i--;
            }
        }
    }
    addressinformation2(1,primaryAddressval,that.nextElementSibling)//渲染二级类
}
function renderdata(classNum, parentId, e) {
    secondaryids=parentId
    secondarybtun=e
    addressinformation2(classNum, parentId, e)//渲染二级类
}
//二级全选
function secondaryallselection(){
    var user_data2 = {
        level: '102',
        parentCode:secondaryids
    }
    var succCallBack2 = function (data, status, response) {
        if($("#secondaryallselection").is(':checked') == true){
            console.log(secondaryAddress)
            for (var d= 0; d < data.list.length; d++) {
                var categoryId = data.list[d].code;
                if(secondaryAddress!=""){
                    //去重
                    if(secondaryAddress.indexOf(categoryId) == -1){
                        secondaryAddress.push(Number(categoryId))

                    }
                }else {
                    secondaryAddress.push(Number(categoryId))
                }

            }
        }else {
            for (var i = 0; i < secondaryAddress.length; i++) {
                for (var h = 0; h < data.list.length; h++) {
                    var categoryId = data.list[h].code;
                    if (secondaryAddress[i] == categoryId) {
                        secondaryAddress.splice(i, 1);
                        i--;
                    }
                }
            }
        }
        addressinformation2(2,secondaryids,secondarybtun)

    };
    return web.doAjax(root.member.getLowerAddress, 'post', user_data2, succCallBack2);
}
//二级分类
function addressinformation2(classNum, parentId, e) {
    if(e.previousElementSibling.checked){
        var checkbox = e.previousElementSibling;
        $("#addressdiv2").css({
            display: "block"
        });
        var user_data = {
            level: '102',
            parentCode:parentId
        }
        var succCallBack = function (data, status, response) {
            if (data.list.length == 0) {
                $("#address2").html('<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" >无数据</li>');
            }
            else {
                var address2=''
                //有数据
                for (var i = 0; i < data.list.length; i++) {
                    if(classNum==1){
                        secondaryAddress.push(Number(data.list[i].code))
                    }
                    var codedata=data.list[i]
                    var categoryId = codedata.code;
                    if (checkbox.checked) {
                        if ($.inArray(Number(categoryId), secondaryAddress) != -1) {
                            address2+='<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5" ><input onclick="selectdata2(this,' + codedata.code + ',' + parentId + ')"  type="checkbox"  value="' + codedata.code + '" checked="checked" class="addressinformations" /><label class="pl-10 secondlevel"  >' + codedata.name + '</label></div></li>'
                        } else {
                            address2+='<li class="removeEl2 clearfix pl-10 mb-5"  style="width: 95%" ><div class="f-l pd-5"><input onclick="selectdata2(this,' + codedata.code + ',' + parentId + ')"  name=""  type="checkbox"  value="' + codedata.code + '"  class="addressinformations" /><label class="pl-10 secondlevel"> ' + codedata.name + '</label></div></li>'
                        }
                    }

                }
                $("#address2").html(address2)

                var ressindata= data.list.length
                ressindatalength=ressindata
                var checkbox2 = $(".addressinformations");
                var checked_counts = 0;
                for(var x=0;x<checkbox2.length;x++){
                    if(checkbox2[x].checked){     //被选中的checkbox
                        checked_counts++;
                    }
                }
                if(ressindata==checked_counts){
                    $("#secondaryallselection").prop("checked","checked")
                }else {
                    $("#secondaryallselection").prop("checked",false)
                }

            }
        };
        return web.doAjax(root.member.getLowerAddress, 'post', user_data, succCallBack);
    }else {
        var user_data2 = {
            level: '102',
            parentCode:parentId
        }
        var succCallBack2 = function (data, status, response) {
            for (var i = 0; i < secondaryAddress.length; i++) {
                for (var h = 0; h < data.list.length; h++) {
                    var categoryId = data.list[h].code;
                    if (secondaryAddress[i] == categoryId) {
                        secondaryAddress.splice(i, 1);
                        i--;
                    }
                }
            }

        };
        return web.doAjax(root.member.getLowerAddress, 'post', user_data2, succCallBack2);

    }
}
function selectdata2(that,valCode,parentId) {
    var secondaryAddressval = parseInt(that.value);
    if(that.checked){
        secondaryAddress.push(Number(secondaryAddressval))
    } else{
        for (var i = 0; i < secondaryAddress.length; i++) {
            if (secondaryAddress[i] == secondaryAddressval) {
                secondaryAddress.splice(i, 1);
                i--;
            }
        }
    }

    var checkbox2 = $(".addressinformations");
    var checked_counts = 0;
    for(var x=0;x<checkbox2.length;x++){
        if(checkbox2[x].checked){     //被选中的checkbox
            checked_counts++;
        }
    }
    if(ressindatalength==checked_counts){
        $("#secondaryallselection").prop("checked","checked")
    }else {
        $("#secondaryallselection").prop("checked",false)
    }
}

//确定
function floorInformation() {
    console.log('一级'+primaryClassification)
    console.log('二级'+secondaryClassification)
    console.log('三级'+tertiaryClassification)
    console.log('四级'+levelfourClassification)
    return false
    if($("#amount").val()==""){
        $.Huimodalalert('请填写订单商品金额',2000);
        return false;
    }
    if(primaryClassification==""){
        $.Huimodalalert('请选择一级分类名称',2000);
        return false;
    }
    if(secondaryClassification==""){
        $.Huimodalalert('请选择二级分类名称',2000);
        return false;
    }
    if(tertiaryClassification==""){
        $.Huimodalalert('请选择三级分类名称',2000);
        return false;
    }
    if(levelfourClassification==""){
        $.Huimodalalert('请选择四级分类名称',2000);
        return false;
    }
    if(primaryAddress==""){
        $.Huimodalalert('请选择一级地址范围',2000);
        return false;
    }
    if(secondaryAddress==""){
        $.Huimodalalert('请选择二级地址范围',2000);
        return false;
    }
    $.ajax({
        url:root.logistics.freeFreight,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        contentType: "application/json",
        data: JSON.stringify({
            "amount":$("#amount").val(),
            "status":$("#status").html(),
            "categoryIdOne":primaryClassification,
            "categoryIdTwo":secondaryClassification,
            "categoryIdThree":tertiaryClassification,
            "categoryId":levelfourClassification,
            "provinceCode":primaryAddress,
            "cityCode":secondaryAddress,

        }),
        success: function (data) {
            if(data.errorCode==0){
                layer.msg("设置成功", {
                    icon: 6,
                    time: 1000
                }, function() {
                    freeFreight();
                });
            }else {

                $.Huimodalalert(data.msg,2000);
            }
        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}


